﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using CarFrameWork.Common;
namespace CarFrameWork.Model
{
	/// <summary>
	/// 类TaskRelease。
	/// </summary>
	[Serializable]
	public partial class TaskRelease
	{
		public TaskRelease()
		{}
		#region Model
		private int _id;
		private string _taskname;
		private DateTime _starttime;
		private DateTime _endtime;
		private int _tasktype;
		private string _caption;
		private bool _tasktag;
		/// <summary>
		/// 
		/// </summary>
		public int ID
		{
			set{ _id=value;}
			get{return _id;}
		}
		/// <summary>
		/// 
		/// </summary>
		public string TaskName
		{
			set{ _taskname=value;}
			get{return _taskname;}
		}
		/// <summary>
		/// 
		/// </summary>
		public DateTime StartTime
		{
			set{ _starttime=value;}
			get{return _starttime;}
		}
		/// <summary>
		/// 
		/// </summary>
		public DateTime EndTime
		{
			set{ _endtime=value;}
			get{return _endtime;}
		}
		/// <summary>
		/// 
		/// </summary>
		public int TaskType
		{
			set{ _tasktype=value;}
			get{return _tasktype;}
		}
		/// <summary>
		/// 
		/// </summary>
		public string Caption
		{
			set{ _caption=value;}
			get{return _caption;}
		}
		/// <summary>
		/// 
		/// </summary>
		public bool TaskTag
		{
			set{ _tasktag=value;}
			get{return _tasktag;}
		}
		#endregion Model


		#region  Method

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public TaskRelease(int ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,TaskName,StartTime,EndTime,TaskType,Caption,TaskTag ");
			strSql.Append(" FROM [TaskRelease] ");
			strSql.Append(" where ID=@ID ");
			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.Int,4)};
			parameters[0].Value = ID;

			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["ID"]!=null && ds.Tables[0].Rows[0]["ID"].ToString()!="")
				{
					this.ID=int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["TaskName"]!=null && ds.Tables[0].Rows[0]["TaskName"].ToString()!="")
				{
					this.TaskName=ds.Tables[0].Rows[0]["TaskName"].ToString();
				}
				if(ds.Tables[0].Rows[0]["StartTime"]!=null && ds.Tables[0].Rows[0]["StartTime"].ToString()!="")
				{
					this.StartTime=DateTime.Parse(ds.Tables[0].Rows[0]["StartTime"].ToString());
				}
				if(ds.Tables[0].Rows[0]["EndTime"]!=null && ds.Tables[0].Rows[0]["EndTime"].ToString()!="")
				{
					this.EndTime=DateTime.Parse(ds.Tables[0].Rows[0]["EndTime"].ToString());
				}
				if(ds.Tables[0].Rows[0]["TaskType"]!=null && ds.Tables[0].Rows[0]["TaskType"].ToString()!="")
				{
					this.TaskType=int.Parse(ds.Tables[0].Rows[0]["TaskType"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Caption"]!=null && ds.Tables[0].Rows[0]["Caption"].ToString()!="")
				{
					this.Caption=ds.Tables[0].Rows[0]["Caption"].ToString();
				}
				if(ds.Tables[0].Rows[0]["TaskTag"]!=null && ds.Tables[0].Rows[0]["TaskTag"].ToString()!="")
				{
					if((ds.Tables[0].Rows[0]["TaskTag"].ToString()=="1")||(ds.Tables[0].Rows[0]["TaskTag"].ToString().ToLower()=="true"))
					{
						this.TaskTag=true;
					}
					else
					{
						this.TaskTag=false;
					}
				}
			}
		}

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{

		return DbHelperSQL.GetMaxID("ID", "TaskRelease"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from [TaskRelease]");
			strSql.Append(" where ID=@ID ");

			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.Int,4)};
			parameters[0].Value = ID;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add()
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into [TaskRelease] (");
			strSql.Append("TaskName,StartTime,EndTime,TaskType,Caption,TaskTag)");
			strSql.Append(" values (");
			strSql.Append("@TaskName,@StartTime,@EndTime,@TaskType,@Caption,@TaskTag)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@TaskName", SqlDbType.NVarChar,50),
					new SqlParameter("@StartTime", SqlDbType.DateTime),
					new SqlParameter("@EndTime", SqlDbType.DateTime),
					new SqlParameter("@TaskType", SqlDbType.Int,4),
					new SqlParameter("@Caption", SqlDbType.NVarChar),
					new SqlParameter("@TaskTag", SqlDbType.Bit,1)};
			parameters[0].Value = TaskName;
			parameters[1].Value = StartTime;
			parameters[2].Value = EndTime;
			parameters[3].Value = TaskType;
			parameters[4].Value = Caption;
			parameters[5].Value = TaskTag;

			object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update()
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update [TaskRelease] set ");
			strSql.Append("TaskName=@TaskName,");
			strSql.Append("StartTime=@StartTime,");
			strSql.Append("EndTime=@EndTime,");
			strSql.Append("TaskType=@TaskType,");
			strSql.Append("Caption=@Caption,");
			strSql.Append("TaskTag=@TaskTag");
			strSql.Append(" where ID=@ID ");
			SqlParameter[] parameters = {
					new SqlParameter("@TaskName", SqlDbType.NVarChar,50),
					new SqlParameter("@StartTime", SqlDbType.DateTime),
					new SqlParameter("@EndTime", SqlDbType.DateTime),
					new SqlParameter("@TaskType", SqlDbType.Int,4),
					new SqlParameter("@Caption", SqlDbType.NVarChar),
					new SqlParameter("@TaskTag", SqlDbType.Bit,1),
					new SqlParameter("@ID", SqlDbType.Int,4)};
			parameters[0].Value = TaskName;
			parameters[1].Value = StartTime;
			parameters[2].Value = EndTime;
			parameters[3].Value = TaskType;
			parameters[4].Value = Caption;
			parameters[5].Value = TaskTag;
			parameters[6].Value = ID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from [TaskRelease] ");
			strSql.Append(" where ID=@ID ");
			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.Int,4)};
			parameters[0].Value = ID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public void GetModel(int ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,TaskName,StartTime,EndTime,TaskType,Caption,TaskTag ");
			strSql.Append(" FROM [TaskRelease] ");
			strSql.Append(" where ID=@ID ");
			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.Int,4)};
			parameters[0].Value = ID;

			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["ID"]!=null && ds.Tables[0].Rows[0]["ID"].ToString()!="")
				{
					this.ID=int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["TaskName"]!=null && ds.Tables[0].Rows[0]["TaskName"].ToString()!="")
				{
					this.TaskName=ds.Tables[0].Rows[0]["TaskName"].ToString();
				}
				if(ds.Tables[0].Rows[0]["StartTime"]!=null && ds.Tables[0].Rows[0]["StartTime"].ToString()!="")
				{
					this.StartTime=DateTime.Parse(ds.Tables[0].Rows[0]["StartTime"].ToString());
				}
				if(ds.Tables[0].Rows[0]["EndTime"]!=null && ds.Tables[0].Rows[0]["EndTime"].ToString()!="")
				{
					this.EndTime=DateTime.Parse(ds.Tables[0].Rows[0]["EndTime"].ToString());
				}
				if(ds.Tables[0].Rows[0]["TaskType"]!=null && ds.Tables[0].Rows[0]["TaskType"].ToString()!="")
				{
					this.TaskType=int.Parse(ds.Tables[0].Rows[0]["TaskType"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Caption"]!=null && ds.Tables[0].Rows[0]["Caption"].ToString()!="")
				{
					this.Caption=ds.Tables[0].Rows[0]["Caption"].ToString();
				}
				if(ds.Tables[0].Rows[0]["TaskTag"]!=null && ds.Tables[0].Rows[0]["TaskTag"].ToString()!="")
				{
					if((ds.Tables[0].Rows[0]["TaskTag"].ToString()=="1")||(ds.Tables[0].Rows[0]["TaskTag"].ToString().ToLower()=="true"))
					{
						this.TaskTag=true;
					}
					else
					{
						this.TaskTag=false;
					}
				}
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select * ");
			strSql.Append(" FROM [TaskRelease] ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		#endregion  Method
	}
}

